<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel app\models\MdspartsSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

//$this->title = 'Category';
$labels = array(
    'Category','Category_sub','Category_sub_sub'
);
$this->title = $labels[$level];

$this->params['breadcrumbs'][] = $level != 0 ? [
    'label' => 'Category',
    'url' => ['list','level'=>0]
] : 'Category';

$this->params['breadcrumbs'][] = $level != 1 ? [
    'label' => 'Category_sub',
    'url' => ['list','level'=>1]
] : 'Category_sub';
$this->params['breadcrumbs'][] = $level != 2 ? [
    'label' => 'Category_sub_sub',
    'url' => ['list','level'=>2]
] : 'Category_sub_sub';
?>
<div class="mdsparts-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('Create Category', ['create'], ['class' => 'btn btn-success']) ?>
    </p>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            'id',
            'title',
            'slug',
//            [
//                'class' => 'yii\grid\ActionColumn',
//            ],
            [
                'label'=>'操作',
                'format'=>'raw',
                'value' => function($data){
                    $className = get_class( $data );
                    $table = explode('\\', $className)[2];
                    $levels = array(
                        'Category'=>0,
                        'CategorySub'=>1,
                        'CategorySubSub'=>2,
                    );
                    $editUrl = "/backend/web/index.php?r=category/update&id="
                        .$data->id.'&level='. $levels[$table];
                    $viewUrl = "/backend/web/index.php?r=category/view&id="
                        .$data->id.'&level='. $levels[$table];
                    $delUrl = "/backend/web/index.php?r=category/delete&id="
                        .$data->id.'&level='. $levels[$table];
                    return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $viewUrl )
                    . Html::a('<span class="glyphicon glyphicon-pencil"></span>', $editUrl )
                    . Html::a('<span class="glyphicon glyphicon-trash"></span>', $delUrl );
                }
            ]
        ],
    ]); ?>
</div>
